<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看商品</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
	$(function() {
		$.post("${pageContext.request.contextPath}/itemSelect",
				function(data) {
					$.each(data, function(n, item) {
						var column = '<option value= '+item.categoryId+'>'
								+ item.categoryName + '</option>';
						$("#selectCategory").append(column);
					});
				}, "json");
	});
	
	//点击查询，进行条件查询
	$(function(){
		$("#criteriaQuery").click(function(){
			var selectedId=$("#selectCategory").val();
			$.post("${pageContext.request.contextPath}/criteriaShoplist",
					{categoryId:selectedId},
					function(data){
						$("tbody").empty();//删除子元素
						$.each(data,function(n, item){
							$("tbody").append("<tr>");
							var url = "${pageContext.request.contextPath}/shopEdit?shopId="+item.shop.shopId;
							var content = '<td>'+(n+1)+'</td><td>'+item.shop.shopName+'</td><td>'+item.shop.shopPrice+'</td>'+
										'</td><td>'+item.shop.shopCount+'</td><td>'+item.shop.shopCategoryName+'</td><td>'+
										'<a href='+url+'>修改</a></td>';
							$("tbody").append(content);
							$("tbody").append();
							$("tbody").append("</tr>");
						});
					},
					"json");
		});
	});
	
</script>
</head>
<body>
	<div>
		商品分类选择： <select id="selectCategory">
			<option value="0">--请选择--</option>
		</select>
		<input id="criteriaQuery" type="button" value="查询">
	</div>
	<table>
		<thead>
			<tr>
				<th>序号</th>
				<th>商品名</th>
				<th>价格</th>
				<th>数量</th>
				<th>类别</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="item" items="${allShop}" varStatus="i">
				<tr>
					<td>${i.count}</td>
					<td>${item.shop.shopName}</td>
					<td>${item.shop.shopPrice}</td>
					<td>${item.shop.shopCount}</td>
					<td>${item.shop.shopCategoryName}</td>
					<td><a href="${pageContext.request.contextPath}/shopEdit?shopId=${item.shop.shopId}">修改</a></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</body>
</html>